﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using MasterDetailTemplate.Views;
using Xamarin.Forms;

namespace MasterDetailTemplate.Services {
    /// <summary>
    /// 根导航服务接口。
    /// By XJ
    /// </summary>
    /// <seealso cref="GalaSoft.MvvmLight.Views.INavigationService"/>
    public interface IRootNavigationService {
        /// <summary>
        /// Instructs the navigation service to display a new page
        /// corresponding to the given key. Depending on the platforms,
        /// the navigation service might have to be configured with a
        /// key/page list.
        /// </summary>
        /// <param name="pageKey">页面键。</param>
        Task NavigateToAsync(string pageKey);

        /// <summary>
        /// Instructs the navigation service to display a new page
        /// corresponding to the given key, and passes a parameter
        /// to the new page.
        /// Depending on the platforms, the navigation service might 
        /// have to be Configure with a key/page list.
        /// </summary>
        /// <param name="pageKey">页面键。</param>
        /// <param name="parameter">参数。</param>
        Task NavigateToAsync(string pageKey, object parameter);
    }


    /// <summary>
    /// 根导航服务常量。
    /// </summary>
    public static class RootNavigationServiceConstants {

        public const string InitializationPage =
            nameof(Views.InitializationPage);

        public const string HomePage = nameof(Views.HomePage);

        public const string AddEventPage = nameof(Views.AddEventPage);

        public const string AnniversaryPage = nameof(Views.AnniversaryPage);

        public const string AnniversarySearchPage =
            nameof(Views.AnniversarySearchPage);

        public const string CountdownSearchPage =
            nameof(Views.CountdownSearchPage);

        public const string SearchPage = nameof(Views.SearchPage);

        public const string TimelinePage =
            nameof(Views.TimelinePage);

        public const string DataSynchronizationPage =
            nameof(Views.DataSynchronizationPage);

        public static readonly ReadOnlyDictionary<string, Type>
            PageKeyTypeDictionary = new ReadOnlyDictionary<string, Type>(
                new Dictionary<string, Type> {
                    [InitializationPage] = typeof(InitializationPage),
                    [HomePage] = typeof(HomePage),
                    [AddEventPage] = typeof(AddEventPage),
                    [AnniversaryPage] = typeof(AnniversaryPage),
                    [AnniversarySearchPage] = typeof(AnniversarySearchPage),
                    [CountdownSearchPage] = typeof(CountdownSearchPage),
                    [SearchPage] = typeof(SearchPage),
                    [TimelinePage] = typeof(TimelinePage),
                    [DataSynchronizationPage] = typeof(DataSynchronizationPage)
                });
    }

    /// <summary>
    /// 根导航消息。
    /// </summary>
    public class RootNavigationMessage {
        public string PageKey { get; set; }
    }
}